package com.stu.controller;

import com.stu.maphandler.SelectChooser;
import com.stu.strategy.AbstractDisplay;
import com.stu.strategy.Display;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author MI
 * @ClassName StrategyController.java
 * @createTime 2022年01月10日 15:35:00
 */
@Slf4j
@Api(tags = "策略测试")
@RestController
@RequestMapping("/strategy")
public class StrategyController {
	@Autowired
	private final Map<String, AbstractDisplay> strategyMap = new ConcurrentHashMap<>(3);
	//stringDisplay
	@Autowired
	Display display;
	@Autowired
	@Qualifier("charDisplay")
	AbstractDisplay abstractDisplay;

	@Autowired
	SelectChooser selectChooser;

	@GetMapping
	@ApiOperation(value = "策略测试", notes = "策略测试")
	public void display(String strategy) {
		display.factory(strategy);
		display.calcDistance();
		System.out.println("抽象类" + abstractDisplay);
	}

	@GetMapping("testMap")
	@ApiOperation(value = "map注入", notes = "策略测试")
	public void map() {
		strategyMap.forEach((k, v) -> {
			log.info("key=[{}]  value=[{}]", k, v);
		});
	}

	@GetMapping("sel")
	public void sel() {
		selectChooser.select("a").apply(RandomStringUtils.randomAlphabetic(5));
	}
}
